<?php

class SettingsController extends Controller
{
	public function actionProfile()
	{
		$company_id = Yii::app()->user->getState('organization_id');
		$model= Organization::model()->findByPk($company_id);

		if(isset($_POST['Organization']))
		{
			$model->attributes=$_POST['Organization'];
			if($model->save())
			{
				Yii::app()->user->setFlash('notify',"Your profile has been updated.");
				$this->refresh();
			}

		}

		$this->render('profile',array(
			'model'=>$model,
		));
		
	}

	public function actionStaff()
	{
		$this->render('staff');
	}
	
	public function actionMisc()
	{
		$company_id = Yii::app()->user->getState('organization_id');
		$model= OrganizationSettings::model()->findByPk($company_id);
		
		if(isset($_POST['OrganizationSettings']))
		{
			$model->attributes=$_POST['OrganizationSettings'];
			if($model->save())
			{
				
				// update user state with new stored settings
				Yii::app()->user->setState('quantity_decimals', $model->quantity_decimal_place);
				Yii::app()->user->setState('amount_decimals', $model->amount_decimal_place);
				
				Yii::app()->user->setFlash('notify',"Your settings have been updated.");
				$this->refresh();
			}

		}
		
		$this->render('misc', array('model'=>$model));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}